package open.template.work.commons.constants;

import java.util.concurrent.ConcurrentHashMap;

/**
 * 微服务目录
 */
public class CloudServerDirectory {

    /**
     * udm服务端应用名
     */
    public static final String UDM_SERVER = "UDM-SERVER";

    public static final String UDM_CLIENT = "UDM-CLIENT";


    private static final ConcurrentHashMap<String, String> urlMap = new ConcurrentHashMap<>();


    /**
     * 根据服务端应用名获取应用url路径，目前只有restful地址
     * @param key
     * @return
     */
    public static String getServerUrl(String key) {
        if (!urlMap.contains(key)) {
            urlMap.put(key, "http://" + key + "/");
            urlMap.get(key);
        }

        return urlMap.get(key);
    }

    /**
     * 根据服务端应用名获取应用url路径，目前只有restful地址
     * @param ip,port
     * @return
     */
    public static String getServerUrl(String ip,int port) {
        String key=ip+port;
        if (!urlMap.contains(ip+port)) {
            urlMap.put(key,String.format("http://%s:%s/",ip,port));
            urlMap.get(key);
        }
        System.out.println("最终url="+urlMap.get(key));
        return urlMap.get(key);
    }

}
